<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>退货</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/logic/materialback";
		var basic_WUrl="logic/materialback";
		var basic_Title="退货管理";
		var show_Width=950;
		var show_Hight=400;
		var user='${user.name}';
		function createSearch(){
			init(1,8,'100,100,100,100,100,100,100,100','25%');
			//第一行的数据
			addCommon(0,0,"lable","退料单号");
			addCommon(0,1,"txtlike","zd001Code");
			addCommon(0,2,"lable","PI号：");
			addCommon(0,3,"txtlike","zd007PiCode");
			addCommon(0,4,"lable","制单人");
			addCommon(0,5,"txtlike","zd009Aegnt");
			addCommon(0,6,"lable","单据状态：");
			addCommon(0,7,"selectEnum","zd003Statue","<option></option><option value='MRCK_SAVE'>草稿</option>"+
					"<option value='MRCK_COMP'>审批中</option><option value='MRCK_AUDIT'>完成</option><option value='MRCK_BACK'>退回</option>");
		
			init(2,8,'100,100,100,100,100,100,100,100','25%');
			addCommon(1,0,"lable","反审单号");
			addCommon(1,1,"txtlike","zd005OriCode");
		}
		function searchAP(){			
			multipleSearch("#table1",true,"",basic_Url+"/list.do");
		}
		document.onkeydown=keyListener;   
		function keyListener(e){   
		    e = e ? e : event;  
		    if(e.keyCode == 13){   
		    	searchAP();
		    }   
		}
		$(function(){
			var grid = $("#table1").ligerGrid({
		        columns: [{ display: '退货单号', name: 'zd001Code', width: 120 },
		                  { display: '反审单号', name: 'zd005OriCode', width: 120 },
		                  { display: '仓库名称', name: 'zd006WhName', width: 80},
		                  { display: '单据状态', name: 'zd003Statue', width: 80, render: function (item){
		                	  if(item.zd003Statue=='MRCK_SAVE'){
		                		  return '草稿';
		                	  }else if(item.zd003Statue=='MRCK_COMP'){
		                		  return '已提交';
		                	  }else if(item.zd003Statue=='MRCK_AUDIT'){
		                		  return '审核完成';
		                	  }else if(item.zd003Statue=='MRCK_BACK'){
		                		  return '已退回';
		                	  }
		                  }},
		                  { display: 'PI编号', name: 'zd007PiCode', width: 100}, 
		                  { display: '客户/供应商名称', name: 'zd008CompName', width: 200},
		                  { display: '创建人', name: 'bizCreatorName', width: 80},
		                  { display: '退货日期', name: 'zd004Date', width: 80,
		                	  render: function (item){
		                		  var zd004Date=new Date(item.zd004Date);
		                		  return formatDate(zd004Date,"yyyy-MM-dd");
		                	  }},
		                  { display: '备注', name: 'zd011ReMark', width: 150 }
		                      ],  usePager: true,pageSize:15,pageSizeOptions :[15,30,45,60],enabledSort:false,
		                      url : basic_Url+"/list.do",
		                      width: "100%", height:"98%", checkbox: true,rownumbers:true,      
		                      onDblClickRow : function (data, rowindex, rowobj){
		                    	  edit(data);
		                       }
		                  });
			$("#pageloading").hide();
		});
		function checkdel(){
			var manager = $("#table1").ligerGetGridManager(); 
			var rows = manager.getSelectedRows();
			var bol = false;
			if (rows==null||rows.length==0){
				$.dialog.alert('请选择需要操作删除的行！');
				return;
			}else{
				
				for(var i=0;i<rows.length;i++){
				 	if (rows[i].bizCreatorName !='${user.name}'){
				 		bol = true;
					}
				}
				if(bol){
					$.dialog.alert('只能对本人建的单据进行删除操作!');
					return;
				}else{
					bol = false;
					for(var i=0;i<rows.length;i++){
					 	if (rows[i].zd003Statue == 'MRCK_SAVE' || rows[i].zd003Statue =='MRCK_BACK'){
					 		bol = true;
						}
					}
					if(bol){
						del();
						bol = false;
					}else{
						$.dialog.alert('草稿或已退回状态的单据才能进行删除!');
						return;
					}
				}
			}
		}
	</script>
  </head>
<body onload="createSearch()">
   <div id="layout1">
      <div>
          <div class="panelBar">
	           <ul class="toolBar">
	             
		           <li><a class="add" onclick="add()">
		           <span>添加</span></a></li>
				   <li><a class="delete" onclick="checkdel()"><span>删除</span></a></li>
               </ul>
          </div>
          <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
      </div>
      <div position="center" id="table1">
      </div>
      <div class="clear"></div>
   </div>
 
</body>
</html>